home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 23 / CU Amiga - Super CD-ROM 23 (June 1998).iso / CreatingGames / Utilities / Misc / GMS / GMSDev / Source / Asm / Demos / RainingBobs.s < prev    next >
Encoding:
Text File  |  1997-12-16  |  8.4 KB  |  353 lines

  1. ;-------T-------T------------------------T----------------------------------;
  2. ;Name:      Raining Bob's Demo
  3. ;Author:    Paul Manias
  4. ;Copyright: DreamWorld Productions (c) 1996-1997.  Freely distributable.
  5. ;
  6. ;This is a demonstration of raining bobs, which I use as a test routine to
  7. ;see how fast some of my blitter routines are.  It's a good example of using
  8. ;MBOB's, try out different MAX_IMAGES values to see how many you can get on
  9. ;screen.  **120** 16 colour 16x8 bobs just manage to run at full speed on my
  10. ;A1200+FAST, change the value if you have a faster machine (600 can be very
  11. ;interesting :-).
  12. ;
  13. ;Technical notes
  14. ;---------------
  15. ;This demo takes direct advantage of some special GMS blitting features,
  16. ;such as restorelist clearing without masks (gain: 10%), and 16 pixel
  17. ;alignment (gain: 15%).  That allows us to have 25% more BOB's on screen!
  18. ;
  19. ;The fact that GMS will use the CPU to draw and clear images when the blitter
  20. ;is busy gives a boost of about 20%+ on an '020, so the overall advantage
  21. ;over a bog standard blitting function (eg BltBitmap()) is at least 40%.
  22. ;Given that such a function would have to be called 120 times with newly
  23. ;calculated parameters each time to draw, and 120 times to do the clears, we
  24. ;are probably looking at least 65% faster... is that good enough?
  25.  
  26.     INCDIR    "INCLUDES:"
  27.     INCLUDE    "dpkernel/dpkernel.i"
  28.  
  29. MAX_IMAGES =    120
  30.  
  31.     SECTION    "Demo",CODE
  32.  
  33. ;===========================================================================;
  34. ;                             INITIALISE DEMO
  35. ;===========================================================================;
  36.  
  37.     STARTDPK
  38.  
  39. Start:    MOVEM.L    A0-A6/D1-D7,-(SP)
  40.     move.l    DPKBase(pc),a6
  41.     lea    TAGS_BobsPicture(pc),a0
  42.     sub.l    a1,a1
  43.     CALL    Init
  44.     tst.l    d0
  45.     beq.s    .Exit
  46.  
  47.     move.l    PIC_Bobs(pc),a1
  48.     move.l    a1,RainPic
  49.     move.l    PIC_Bitmap(a1),a2
  50.     move.l    BMP_AmtColours(a2),GColours
  51.     move.l    PIC_Palette(a1),GPalette
  52.  
  53.     lea    ScreenTags(pc),a0
  54.     sub.l    a1,a1
  55.     CALL    Init
  56.     move.l    d0,Screen
  57.     beq.s    .Exit
  58.  
  59.     lea    RestoreTags(pc),a0
  60.     move.l    Screen(pc),a1    ;a1 = Screen.
  61.     CALL    Init    ;>> = Initialise the restore list.
  62.     tst.l    d0    ;d0 = Check for errors.
  63.     beq.s    .Exit    ;>> = Error, exit.
  64.  
  65.     lea    TAGS_RainBob(pc),a0
  66.     move.l    Screen(pc),a1
  67.     move.l    GS_Bitmap(a1),a1
  68.     CALL    Init    ;>> = Initialise the Bob.
  69.     tst.l    d0
  70.     beq.s    .Exit
  71.  
  72.     moveq    #ID_JOYDATA,d0    ;Get joydata structure.
  73.     CALL    Get
  74.     move.l    d0,JoyData
  75.     beq.s    .Exit
  76.     move.l    d0,a0    ;Initialise the joydata structure.
  77.     sub.l    a1,a1
  78.     CALL    Init
  79.     tst.l    d0
  80.     beq.s    .Exit
  81.  
  82.     move.l    Screen(pc),a0
  83.     CALL    Display
  84.  
  85.     bsr.s    Main
  86.  
  87. .Exit    move.l    DPKBase(pc),a6
  88.     move.l    JoyData(pc),a0
  89.     CALL    Free
  90.     move.l    MBOB_Rain(pc),a0
  91.     CALL    Free
  92.     move.l    Restore(pc),a0
  93.     CALL    Free
  94.     move.l    Screen(pc),a0
  95.     CALL    Free
  96.     move.l    PIC_Bobs(pc),a0
  97.     CALL    Free
  98.     MOVEM.L    (SP)+,A0-A6/D1-D7
  99.     moveq    #ERR_OK,d0
  100.     rts
  101.  
  102. ;===========================================================================;
  103. ;                                DEMO CODE
  104. ;===========================================================================;
  105.  
  106. Main:    moveq    #$00,d7
  107.     move.l    MBOB_Rain(pc),a1
  108.  
  109.     move.l    Screen(pc),a0    ;a0 = Screen.
  110.     move.l    MB_EntryList(a1),a2    ;a2 = First entry.
  111.     move.w    MB_AmtEntries(a1),d2
  112.     subq.w    #1,d2
  113. .create    bsr    RegenerateBob
  114.  
  115.     move.l    DPKBase(pc),a6
  116.     move.w    GS_Height(a0),d1
  117.     CALL    FastRandom
  118.     move.w    d0,BE_YCoord(a2)
  119.  
  120.     lea    NBE_SIZEOF(a2),a2
  121.     dbra    d2,.create
  122.  
  123. ;---------------------------------------------------------------------------;
  124. ;                                     MAIN LOOP
  125. ;---------------------------------------------------------------------------;
  126.  
  127. Loop:    move.l    Screen(pc),a0    ;a0 = Screen.
  128.     move.l    MBOB_Rain(pc),a1
  129.     addq.w    #1,d7
  130.     move.l    MB_EntryList(a1),a2    ;a2 = First entry.
  131.     move.w    MB_AmtEntries(a1),d2
  132.     subq.w    #1,d2
  133. .update    bsr.s    UpdateBob
  134.     lea    NBE_SIZEOF(a2),a2
  135.     dbra    d2,.update
  136.  
  137.     move.l    DPKBase(pc),a6
  138.     move.l    Restore(pc),a0
  139.     CALL    Activate
  140.  
  141.     move.l    MBOB_Rain(pc),a0    ;a0 = Bob to draw.
  142.     CALL    Draw    ;>> = Draw the mbob.
  143.  
  144.     move.l    SCRBase(pc),a6
  145.     CALL    scrWaitAVBL
  146.  
  147.     move.l    Screen(pc),a0
  148.     CALL    scrSwapBuffers
  149.  
  150.     move.l    DPKBase(pc),a6
  151.     move.l    JoyData(pc),a0
  152.     CALL    Query
  153.     move.l    JoyData(pc),a0
  154.     move.l    JD_Buttons(a0),d0
  155.     btst    #JB_LMB,d0
  156.     beq.s    Loop
  157.     rts
  158.  
  159. ;===========================================================================;
  160. ;                               UPDATE A BOB
  161. ;===========================================================================;
  162. ;Function: Moves the entity according to its internal settings.
  163. ;Requires: a1 = Bob structure.
  164. ;       a2 = Entry to update.
  165.  
  166. UpdateBob:
  167.     move.w    BE_YCoord(a2),d0    ;d0 = YCoord
  168.     add.w    BE_Speed(a2),d0    ;d0 = (YCoord)+YSpeed
  169.     cmp.w    GS_Height(a0),d0
  170.     blt.s    .YOkay
  171.     bsr    RegenerateBob
  172.     bra.s    .Animate
  173. .YOkay    move.w    d0,BE_YCoord(a2)
  174.  
  175. .Animate
  176.     tst.w    BE_Locked(a2)
  177.     beq.s    .exit
  178.     move.w    d7,d6
  179.     and.w    #%00000011,d6
  180.     bne.s    .exit
  181.     move.w    BE_FChange(a2),d1
  182.     bgt.s    .Positive
  183.  
  184. .Negative
  185.     cmp.w    #1,BE_Set(a2)
  186.     bgt.s    .NBlue
  187.     beq.s    .NGreen
  188. .NRed    add.w    d1,BE_Frame(a2)
  189.     tst    BE_Frame(a2)
  190.     bge.s    .exit
  191.     move.w    #1,BE_FChange(a2)
  192.     clr.w    BE_Frame(a2)
  193.     rts
  194. .NGreen    add.w    d1,BE_Frame(a2)
  195.     cmp.w    #4,BE_Frame(a2)
  196.     bge.s    .done
  197.     move.w    #1,BE_FChange(a2)
  198.     move.w    #4,BE_Frame(a2)
  199.     rts
  200. .NBlue    add.w    d1,BE_Frame(a2)
  201.     cmp.w    #8,BE_Frame(a2)
  202.     bge.s    .done
  203.     move.w    #1,BE_FChange(a2)
  204.     move.w    #8,BE_Frame(a2)
  205. .exit    rts
  206.  
  207. .Positive
  208.     cmp.w    #1,BE_Set(a2)
  209.     bgt.s    .PBlue
  210.     beq.s    .PGreen
  211. .PRed    add.w    d1,BE_Frame(a2)
  212.     cmp.w    #3,BE_Frame(a2)
  213.     ble.s    .done
  214.     move.w    #-1,BE_FChange(a2)
  215.     move.w    #2,BE_Frame(a2)
  216.     rts
  217. .PGreen    add.w    d1,BE_Frame(a2)
  218.     cmp.w    #7,BE_Frame(a2)
  219.     ble.s    .done
  220.     move.w    #-1,BE_FChange(a2)
  221.     move.w    #6,BE_Frame(a2)
  222.     rts
  223. .PBlue    add.w    d1,BE_Frame(a2)
  224.     cmp.w    #11,BE_Frame(a2)
  225.     ble.s    .done
  226.     move.w    #-1,BE_FChange(a2)
  227.     move.w    #10,BE_Frame(a2)
  228. .done    rts
  229.  
  230. ;===========================================================================;
  231. ;                            REGENERATE BOB ENTITY
  232. ;===========================================================================;
  233. ;Function: Regenerates an entity with completely new data.
  234. ;Requires: a2 = Entry to update.
  235.  
  236. RegenerateBob:
  237.     move.l    DPKBase(pc),a6
  238.     move.w    GS_Width(a0),d1
  239.     CALL    FastRandom
  240.     subq.w    #4,d0
  241.     and.w    #%1111111111111000,d0
  242.     move.w    d0,BE_XCoord(a2)
  243.  
  244.     moveq    #8,d1
  245.     CALL    FastRandom
  246.     addq.w    #2,d0
  247.     move.w    d0,BE_Speed(a2)
  248.  
  249.     moveq    #12,d1
  250.     CALL    FastRandom
  251.     move.w    d0,BE_Frame(a2)
  252.     move.b    .Sets(pc,d0.w),BE_Set+1(a2)
  253.  
  254.     move.w    #-8,BE_YCoord(a2)
  255.     move.w    #1,BE_FChange(a2)
  256.     eor.w    #1,BE_Locked(a2)
  257.     rts
  258.  
  259. .Sets    dc.b    0,0,0,0
  260.     dc.b    1,1,1,1
  261.     dc.b    2,2,2,2
  262.  
  263. ;===========================================================================;
  264. ;                                  DATA
  265. ;===========================================================================;
  266.  
  267. JoyData:    dc.l  0
  268.  
  269. RestoreTags:    dc.l  TAGS_RESTORE
  270. Restore:    dc.l  0
  271.         dc.l  RSA_Entries,MAX_IMAGES
  272.         dc.l  TAGEND
  273.  
  274. ;---------------------------------------------------------------------------;
  275.  
  276. ScreenTags:    dc.l  TAGS_SCREEN
  277. Screen:        dc.l  0
  278.         dc.l  GSA_Palette
  279. GPalette:    dc.l  0
  280.         dc.l    GSA_BitmapTags,0
  281.         dc.l    BMA_AmtColours
  282. GColours:    dc.l    0
  283.         dc.l    TAGEND,0
  284.         dc.l  GSA_Attrib,DBLBUFFER
  285.         dc.l  TAGEND
  286.  
  287. ;---------------------------------------------------------------------------;
  288.  
  289. TAGS_BobsPicture:
  290.         dc.l  TAGS_PICTURE
  291. PIC_Bobs:    dc.l  0
  292.         dc.l    PCA_BitmapTags,0
  293.         dc.l    BMA_MemType,MEM_VIDEO
  294.         dc.l    TAGEND,0
  295.         dc.l  PCA_Source,.filename
  296.         dc.l  TAGEND
  297.  
  298. .filename    FILENAME "GMS:demos/data/PIC.Pulse"
  299.  
  300. ;---------------------------------------------------------------------------;
  301.  
  302.   ;This is a mutated entrylist that we use for the raining bobs.
  303.  
  304.   STRUCTURE    NBE,BE_SIZEOF
  305.     WORD    BE_Speed    ;Speed of this particular bob.
  306.     WORD    BE_Set    ;0 = Red, 1 = Green, 2 = Blue.
  307.     WORD    BE_FChange
  308.     WORD    BE_Locked    ;Is it animated or not.
  309.     LABEL    NBE_SIZEOF
  310.  
  311. TAGS_RainBob:    dc.l  TAGS_MBOB
  312. MBOB_Rain:    dc.l  0
  313.         dc.l  MBA_AmtEntries,MAX_IMAGES
  314.         dc.l  MBA_GfxCoords,RainFrames
  315.         dc.l  MBA_Width,8
  316.         dc.l  MBA_Height,8
  317.         dc.l  MBA_EntryList,Images
  318.         dc.l  MBA_Attrib,BBF_CLIP|BBF_GENMASKS|BBF_CLEAR|BBF_CLRNOMASK
  319.         dc.l  MBA_Source
  320. RainPic:    dc.l  0
  321.         dc.l  MBA_EntrySize,NBE_SIZEOF
  322.         dc.l  TAGEND
  323.  
  324. RainFrames:    dc.w   0,8*0    ;RED
  325.         dc.w   0,8*1
  326.         dc.w   0,8*2
  327.         dc.w   0,8*3
  328.         dc.w   8,8*0    ;GREEN
  329.         dc.w   8,8*1
  330.         dc.w   8,8*2
  331.         dc.w   8,8*3
  332.         dc.w  16,8*0    ;BLUE
  333.         dc.w  16,8*1
  334.         dc.w  16,8*2
  335.         dc.w  16,8*3
  336.         dc.l  -1
  337.  
  338. ;---------------------------------------------------------------------------;
  339.  
  340.     SECTION    Images,BSS
  341.  
  342. Images:    ds.b    NBE_SIZEOF*MAX_IMAGES    ;X/Y/Frame/Speed/Set/FChange/Locked
  343.  
  344. ;===========================================================================;
  345.  
  346. ProgName:    dc.b  "Raining Bobs",0
  347. ProgAuthor:    dc.b  "Paul Manias",0
  348. ProgDate:    dc.b  "15 December 1997",0
  349. ProgCopyright:    dc.b  "DreamWorld Productions (c) 1996-1997.  Freely distributable.",0
  350. ProgShort:    dc.b  "Multiple bobs demonstration.",0
  351.         even
  352.  
  353.